package com.sinothk.image.selector;

import android.graphics.Color;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

import androidx.appcompat.app.AppCompatActivity;

import com.sinothk.android.utils.StatusBarUtil;

/**
 * Created by foamtrace on 2015/8/25.
 */
public class VideoShowActivity extends AppCompatActivity {

    private VideoView videoView;
    String url;
    private MediaController mediaController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ms_activity_video_preview);
        StatusBarUtil.transparencyBar(this);
        url = getIntent().getStringExtra("url");

        videoView= (VideoView) findViewById(R.id.videoView);

        mediaController = new MediaController(this);
//        String uri = //"android.resource://" + getPackageName() + "/" + R.raw.aas;
        videoView.setVideoURI(Uri.parse(url));
        videoView.setMediaController(mediaController);
        mediaController.setMediaPlayer(videoView);
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
//                startVideo();
                videoView.requestFocus();
                videoView.start();

                mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
                    @Override
                    public boolean onInfo(MediaPlayer mp, int what, int extra) {
                        //播放第一帧
                        if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START)
                            videoView.setBackgroundColor(Color.TRANSPARENT);
                        return true;
                    }
                });
            }

        });
    }
}
